//package com.lill.system.component;
//
//import java.io.ByteArrayOutputStream;
//import java.io.IOException;
//import java.io.InputStream;
//import java.net.HttpURLConnection;
//import java.net.URL;
//import java.util.HashMap;
//
//import org.json.JSONObject;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//
//import com.baidu.aip.ocr.AipOcr;
//
//public class SysBaiduAipServe {
//	
//	protected static Logger logger = LoggerFactory.getLogger(SysBaiduAipServe.class);
//	
//	public static final String APPID = "22694519";
//    public static final String APIKEY = "d8ONtFPSTok3ws2EImpG5WoZ";
//    public static final String SECRETKEY = "1I5x4Ia26Xu8jO0WP2xPr3SpdYsX7aj4";
//    
//    public static AipOcr getBaiDuClient(){
//    	AipOcr client = new AipOcr(APPID, APIKEY, SECRETKEY);
//    	client.setConnectionTimeoutInMillis(2000);
//    	return client;
//    }
//    
//    public static Object getBaiduContent(String fileUrl,String methodName){
//    	Object result="";
//    	try {
//    		AipOcr client =getBaiDuClient();
//    		HashMap<String, String> options = new HashMap<String, String>();
//    		JSONObject clientResult=null;
//			switch (methodName) {
//				case "drivingLicense"://驾驶证识别
//					options.put("detect_direction", "true");
//					clientResult=client.drivingLicense(getFileUrl2Bytes(fileUrl), options);
//					break;
//				case "plateLicense"://车牌识别
//					options.put("multi_detect", "true");
//					clientResult=client.plateLicense(getFileUrl2Bytes(fileUrl), options);
//					break;
//				case "vehicleLicense"://行驶证识别
//					options.put("detect_direction", "true");
//					clientResult=client.vehicleLicense(getFileUrl2Bytes(fileUrl), options);
//					break;
//				case "idcard"://身份证正面
//					options.put("detect_direction", "true");
//				    options.put("detect_risk", "false");
//				    clientResult=client.idcard(getFileUrl2Bytes(fileUrl),"front",options);
//					break;
//				case "basicGeneral"://通用文字识别
//					options.put("language_type", "CHN_ENG");
//				    options.put("detect_direction", "true");
//				    options.put("detect_language", "true");
//				    options.put("probability", "true");
//				    clientResult=client.basicGeneral(getFileUrl2Bytes(fileUrl),options);
//					break;
//				default:break;
//			}
//			if(null!=clientResult){
//				result=clientResult.toString();
//			}
//		} catch (Exception e) {
//			logger.error(e.getMessage(), e);
//		}
//    	return result;
//    }
//    
//    public static byte[] getFileUrl2Bytes(String url){
//    	InputStream inStream = null;
//    	ByteArrayOutputStream outStream = null;
//        try {
//            URL httpUrl = new URL(url);
//            HttpURLConnection conn = (HttpURLConnection)httpUrl.openConnection();
//            conn.setRequestMethod("GET");
//            conn.setConnectTimeout(5 * 1000);
//            inStream = conn.getInputStream();//通过输入流获取图片数据
//            outStream = new ByteArrayOutputStream();
//            byte[] buffer = new byte[1024];
//            int len = 0;
//            while( (len=inStream.read(buffer)) != -1 ){
//                outStream.write(buffer, 0, len);
//            }
//            return outStream.toByteArray();
//        } catch (Exception e) {
//        	logger.error(e.getMessage(), e);
//        }finally{
//        	try {
//				if(null!=inStream) inStream.close();
//			} catch (IOException e) {
//			}
//        	try {
//        		if(null!=outStream) outStream.close();
//        	} catch (IOException e) {
//        	}
//        }
//        return null;
//    }
//    
//
//}
